$(function() {

	$('.showTrack').on('click', function() {
		var that=this
		popup(this)
		
		var map = new AMap.Map('showlocation', {
			resizeEnable: true,
			zoom: 11,
			center: [118.57, 24.82]
		});
		console.log(encodeURI($(that).closest('tr').data('number')))
		AMapUI.loadUI(['overlay/SimpleMarker'], function(SimpleMarker) {
			$.ajax({
				type: 'post',
				url: '{:url("admin/beidou/cars")}',
				data: {
					number: encodeURI($(that).closest('tr').data('number'))
				},
				success: function(res) {
					console.log(res)
					carloc=res
					console.log(res)
					if(res.code==1){
					driverloc = new SimpleMarker({
						//普通文本
						iconStyle: {
							src: '{$static_dir}/assets/img/car.png',
							style: {
								width: '15px',
								height: '30px'
							}
						},
						position: carloc,
						cont: {}
					});
					console.log('放入地图')
					driverloc.setMap(map);
				}else{
					Err('暂无定位')
				}
				}
			});
		});

	});
	$('.delete-list').on('click', function() {
		popup(this, "{:url('delete')}");

	});
	//启用
	$('.startusing').on('click', function() {
		popup(this, "{:url('state')}");

	});
	//禁用
	$('.forbidden').on('click', function() {
		popup(this, "{:url('state')}");

	});
	$('.car_type').on('click', function() {
		choosecar("{:url('models/index',['op'=>'search'])}")
	});
	$('.choose').on('click', function() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.$('.car_number').attr("value", $(this).data('number'));
		parent.$('.CarId').attr("value", $(this).data('id'));
		if(parent.$('.dispatch-number')) {
			parent.$('.dispatch-number').html($(this).data('number'))
		}
		parent.layer.close(index);

	});
	$('.bind').on('click', function() {
		var loadd = layer.load(1, {
			shade: [0.1, '#fff'] //0.1透明度的白色背景
		});
		var index = parent.layer.getFrameIndex(window.name);
		var carid = $(this).closest('tr').data('id')
		var driverid = parent.$('.driver_id').val();
		$.ajax({
			method: "POST",
			url: "{:url('driver/bind')}",
			data: {
				driver_id: driverid,
				car_id: carid
			},
			success: function(res) {
				layer.close(loadd)
				console.log(res)
				if(res.code == 1) {
					layer.msg('关联成功');
					window.history.go(0)
				} else {
					layer.msg(res.msg);
				}
			}
		})
		//		

	});
	//全选
	$('.check-all').on('click', function() {
		checkall(this)
	});
	$('.check-list').on('click', function() {
		checkall(this)
	});
	//删除多个
	$(".delete-multiple").on('click', function() {
		popup(this, "{:url('delete')}");
	})
	$('.unbind').on('click', function() {
		console.log(window.location.href)
		var loadd = layer.load(1, {
			shade: [0.1, '#fff'] //0.1透明度的白色背景
		});
		var index = parent.layer.getFrameIndex(window.name);
		var carid = $(this).closest('tr').data('id')
		var driverid = parent.$('.driver_id').val();
		$.ajax({
			method: "POST",
			url: "{:url('driver/unbind')}",
			data: {
				driver_id: driverid,
				car_id: carid
			},
			success: function(res) {
				layer.close(loadd)
				if(res.code == 1) {
					layer.msg('解除关联成功');
					window.history.go(0)
				} else {
					layer.msg(res.msg);
				}
			}
		})

	});
})